package com.course.result;


/**
 * 结果控制器
 *
 * @author xjh
 * @date 2021/12/20
 */
public class ResultController {

    public static <T> ResponseDto<T> success(String msg, T o) {
        ResponseDto<T> responseDto = new ResponseDto<>();
        responseDto.setCode(ResultCode.SUCCESS);
        responseDto.setMessage(msg);
        responseDto.setContent(o);
        return responseDto;
    }

    public static ResponseDto<Object> success(String msg) {
        return success(msg, null);
    }

    public static <T> ResponseDto<T> success(T o) {
        return success("成功", o);
    }

    public static ResponseDto<Object> success() {
        return success("成功", null);
    }


    public static ResponseDto<Object> fail(String msg, Object o) {
        ResponseDto<Object> responseDto = new ResponseDto<>();
        responseDto.setCode(ResultCode.FAIL);
        responseDto.setMessage(msg);
        responseDto.setContent(o);
        responseDto.setSuccess(false);
        return responseDto;
    }

    public static ResponseDto<Object> fail(String msg) {
        return fail(msg, null);
    }

    public static ResponseDto<Object> fail() {
        return fail("失败", null);
    }
}
